package guava;

import com.google.common.primitives.Ints;

import java.util.Arrays;
import java.util.List;

/**
 * guava提供了Bytes/Shorts/Ints/Longs/Floats/Doubles/Chars/Booleans这些基本数据类型的扩展支持
 *
 * @author Daniel
 */
public class IntsTest {

    public static void main(String[] args) {

        // 快速创建集合
        List<Integer> list = Ints.asList(1, 3, 5, 7, 9);
        System.out.println("list = " + list);

        // 快速拼接成字符串
        String join = Ints.join(",", 1, 3, 1, 4);
        System.out.println("join = " + join);

        // 两个整型数组合并
        int[] concat = Ints.concat(new int[]{1, 2}, new int[]{2, 3, 4});
        System.out.println("concat = " + Arrays.toString(concat));

        // 取最大值
        int max = Ints.max(concat);
        System.out.println("max = " + max);

        // 最最小值
        int min = Ints.min(concat);
        System.out.println("min = " + min);

        // 翻转
        Ints.reverse(concat);
        System.out.println("concat = " + Arrays.toString(concat));

        // 是否包含指定元素
        boolean contains = Ints.contains(concat, 6);
        System.out.println("contains = " + contains);

        // 集合转换成数组
        int[] ints = Ints.toArray(list);
        System.out.println("toArray = " + Arrays.toString(ints));

    }

}
